package com.ruibang.glass.material.service.impl.cp;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.material.domain.req.bcp.BcpProductsInReq;
import com.ruibang.glass.material.entity.cp.MaterialCPProductsIn;
import com.ruibang.glass.material.mapper.cp.MaterialCPProductsInMapper;
import com.ruibang.glass.material.service.cp.MaterialCPProductsInService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 半成品入库 服务实现类
 * </p>
 *
 * @author mameng
 * @since 2024-04-02
 */
@Service
public class GMaterialCPProductsInServiceImpl extends ServiceImpl<MaterialCPProductsInMapper, MaterialCPProductsIn> implements MaterialCPProductsInService {
    /**
     * 列表
     * @param bcpProductsInReq
     * @return
     */
    @Override
    public IPage<MaterialCPProductsIn> getPage(BcpProductsInReq bcpProductsInReq) {
        LambdaQueryWrapper<MaterialCPProductsIn> queryWrapper = Wrappers.<MaterialCPProductsIn>lambdaQuery();
        if (StringUtils.isNotBlank(bcpProductsInReq.getATypeShelf())) {
            queryWrapper.like(MaterialCPProductsIn::getATypeShelf, bcpProductsInReq.getATypeShelf());
        }
        if (StringUtils.isNotBlank(bcpProductsInReq.getBatchNumber())) {
            queryWrapper.like(MaterialCPProductsIn::getBatchNumber, bcpProductsInReq.getBatchNumber());
        }
        if (StringUtils.isNotBlank(bcpProductsInReq.getProductLine())) {
            queryWrapper.like(MaterialCPProductsIn::getProductLine, bcpProductsInReq.getProductLine());
        }
        if (StringUtils.isNotBlank(bcpProductsInReq.getStatus())) {
            queryWrapper.like(MaterialCPProductsIn::getStatus, bcpProductsInReq.getStatus());
        }
        if (StringUtils.isNotBlank(bcpProductsInReq.getLevelRg())) {
            queryWrapper.like(MaterialCPProductsIn::getLevelRg, bcpProductsInReq.getLevelRg());
        }
        if (StringUtils.isNotBlank(bcpProductsInReq.getLevelFinish())) {
            queryWrapper.like(MaterialCPProductsIn::getLevelFinish, bcpProductsInReq.getLevelFinish());
        }
        if (StringUtils.isNotBlank(bcpProductsInReq.getType())) {
            queryWrapper.like(MaterialCPProductsIn::getType, bcpProductsInReq.getType());
        }
        if (bcpProductsInReq.getUpdateStartDate()!=null) {
            queryWrapper.ge(MaterialCPProductsIn::getUpdateTime, bcpProductsInReq.getUpdateStartDate());
        }
        if (bcpProductsInReq.getUpdateEndDate()!=null) {
            queryWrapper.le(MaterialCPProductsIn::getUpdateTime, bcpProductsInReq.getUpdateEndDate());
        }
        Page<MaterialCPProductsIn> materialWarehouseInfoPage = baseMapper.selectPage(new Page<>(bcpProductsInReq.getPageNo(), bcpProductsInReq.getPageSize()),
                queryWrapper.orderByDesc(MaterialCPProductsIn::getCreateTime)
        );
        return materialWarehouseInfoPage;
    }
}
